<template>
	<Layout style="padding:0 24px 24px;height:100%;">
		<Breadcrumb style="margin:24px 0">
			<BreadcrumbItem>首页</BreadcrumbItem>
			<BreadcrumbItem>流程定义</BreadcrumbItem>
		</Breadcrumb>
		<Form inline>
			<FormItem>
				<Input clearable type="text" placeholder="请输入部署流程名称或说明" v-model="uploadData.name"/>
			</FormItem>
			<FormItem>
				<upload
					:data="uploadData"
					url="/admin/sys/workflow/deployment/deploy" 
					@on-success="onSuccess"></upload>
			</FormItem>
			<FormItem>
				<Input v-model="pageRequest.condition.name" placeholder="搜索部署名称" />
			</FormItem>
			<FormItem>
				<Button type="primary" icon="ios-search" shape="circle" title="查询" @click="list"></Button>
			</FormItem>
		</Form>
		<Content ref="content" style="padding:0px;background:#fff;height:100%">
			<Table :loading="loading" :columns="tableColumns" :data="pageData.content" :height="tableHeight" border>
				<template slot-scope="{ row, index }" slot="action">
					<Button type="error" size="small" style="margin-right: 5px" @click="remove(row)">删除</Button>
					<Button type="warning" size="small" @click="redeploy(row)">重新部署</Button>
				</template>
				<template slot="footer">
					<Page style="margin-left:10px;" :total="pageData.total" :current="pageData.page" :page-size="15" @on-change="changePage"></Page>
				</template>
			</Table>
		</Content>
	</Layout>
</template>

<script language="JavaScript">
import upload from '@/components/upload';
export default {
	components: {
		upload
	},
	data() {
		return {
			tableHeight: 100, // 自适应表格高度
			loading: false, // 加载中
			tableColumns: [
				{
					type: 'selection',
					width: 80
				},
				{
					title: '流程部署ID',
					key: 'id',
					width: 'auto',
					minWidth: 250,
					resizable: true
				},
				{
					title: '流程部署名称',
					key: 'name',
					width: 'auto',
					minWidth: 250,
					resizable: true
				},
				{
					title: '部署时间',
					key: 'deploymentTime',
					width: 'auto',
					minWidth: 250,
					resizable: true
				},
				{
					title: '操作',
					slot: 'action',
					fixed: 'right',
					width: 200
				}
			], // 表格列
			// 分页请求
			pageRequest: {
				page: 1,
				rows: 15,
				sort: 'id:asc',
				condition: {}
			},
			// 分页查询结果
			pageData: {
				page: 1,
				total: 2,
				content: [] // 表格数据
			},
			// 流程部署上传数据
			uploadData: {
				name: ""
			},
		};
	},
	computed: {},
	watch: {},
	created: function() {},
	mounted: function() {
		this.$nextTick(() => {
			this.tableHeight = this.$refs.content.$el.clientHeight;
			this.list();
		});
	},
	methods: {
		// 保存
		save: function() {
			this.$refs['form'].validate(valid => {
				if (valid) {
					this.$request.post(
						'',
						this.info,
						res => {
							this.editModal = false;
							this.list();
						},
						true,
						true
					);
				}
			});
		},
		// 获取列表
		list: function() {
			this.$request.post(
				'/admin/sys/workflow/deployment/list',
				this.pageRequest,
				res => {
					this.pageData = res.data || this.pageData;
				},
				false,
				false
			);
		},
		// 删除
		remove: function(row) {
			this.$Modal.confirm({
				title: '确认？',
				content: '删除后不可恢复，是否继续？',
				onOk: () => {
					this.$request.post(
						'/admin/sys/workflow/deployment/delete',
						row,
						res => {
							this.list();
						},
						true,
						true
					);
				}
			});
		},
		redeploy: function(row) {
			this.$Modal.confirm({
				title: '确认？',
				content: '是否重新部署流程？',
				onOk: () => {
					this.$request.post(
						'/admin/sys/workflow/deployment/redeploy',
						row,
						res => {
							this.list();
						},
						true,
						true
					);
				}
			});
		},
		// 分页
		changePage: function(page) {
			this.pageRequest.page = page;
			this.list();
		},
		// 成功上传
		onSuccess: function(res) {
			if (res.status == 'success') {
				this.list();
			}
		},
	}
};
</script>

<style lang="scss" scoped="scoped"></style>
